﻿@{
    Layout = null;
}

<!DOCTYPE html>

<html class="x-admin-sm">
<head>
    <meta name="viewport" content="width=device-width" />
    <meta charset="UTF-8">
    <title>存货档案</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" />
    <link href="~/Content/X-admin/css/font.css" rel="stylesheet" />
    <link href="~/Content/Scripts/layui/css/layui.css" rel="stylesheet" />
    <link href="~/Content/X-admin/css/xadmin.css" rel="stylesheet" />
    <script src="~/Content/X-admin/js/jquery.min.js"></script>
    <script src="~/Content/X-admin/js/xadmin.js"></script>
    <script src="~/Content/Scripts/System/systemFrame.js"></script>
    <script src="~/Content/Scripts/layui/layui.js"></script>
    <script type="text/html" id="barDemo">
    
            <a title="编辑信息" href="javascript:;" lay-event="icEdit" id="update"><i class="layui-icon">&#xe642;</i></a>
            <a title="删除信息" href="javascript:;" lay-event="icDel" id="del"><i class="layui-icon">&#xe640;</i></a>
      
    </script>

</head>
<body>
    <div class="layui-fluid" >
        <div style="float:left">
            <div id="treeNav" class="demo-tree demo-tree-box" style="width: 200px; height: 500px; overflow: scroll;float:left;"></div>

        </div>
        <div style="float:left;width:78%;">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <form class="layui-form layui-col-space5" name="qForm" id="qForm">
                        <div class="layui-inline layui-show-xs-block">

                            <input type="text" name="proCode" placeholder="存货编码" autocomplete="off" class="layui-input" id="proCode">
                        </div>
                        <div class="layui-inline layui-show-xs-block">

                            <input type="text" name="proName" placeholder="存货名称" autocomplete="off" class="layui-input" id="proName">
                        </div>

                        <div class="layui-inline layui-show-xs-block">
                            <button class="layui-btn" lay-filter="sreach" id="btn-view" type="button" onclick="loadData('')"><i class="layui-icon">&#xe615;</i></button>
                        </div>
                    </form>
                </div>
                <div class="layui-card-header">
                    <button class="layui-btn" id="btn-sync" type="button" onclick="syncData()"><i class="layui-icon">&#xe641;</i>数据同步</button>
                    <button class="layui-btn" id="btn-update" type="button" onclick="addData()"><i class="layui-icon"></i>添加存货</button>
                    @*<button class="layui-btn" id="btn-sync" type="button" onclick="syncDef()"><i class="layui-icon">&#xe641;</i>自由项同步</button>*@
                    <span style="margin-left: 20px; padding: 7px; background-color: #bababa; font-size: Xx-small">数据停用</span>
                </div>

                <div class="layui-card-body layui-table-body layui-table-main" id="layui-table-main">
                    <table class="layui-hide" id="list" lay-filter="list"></table>
                </div>
            </div>


        </div>
    </div>
</body>

</html>

<script>
    var currPage=1
    /**
     * 加载数据
     **/
    function loadData(typeCode) {
        layui.use('table', function () {
            var conditon = JSON.stringify(FormToJson("qForm"));
            var table = layui.table;
            dUrl= "../Basis/GetDataList?condition=" + conditon + "&dataType=ven&typesCode=" + typeCode;
            table.render({
                elem: '#list'
            , cols: [[ //标题栏
                { field: 'proCode', align: 'center',  title: '存货编码', width: '25%' }
                , { field: 'proName', align: 'center', title: '存货名称', width: '35%' }
                , { field: 'spec', align: 'center', title: '规格型号', width: '20%' }
                , { field: 'statusName', align: 'center', title: '是否启用', width: '10%' }
               //, {  title: '操作', width: 90, align: 'center', toolbar: '#barDemo' }
            ]], done: function (res, curr, count) {
                currPage = curr
                TablePowerHide();
                $.each(res['data'], function (i, obj) {
                    var status = obj["status"];
                    if (status == "close") {
                        TableRowColor('layui-table-main', i, '#ffd800');
                    }
                });
            }
            , url:dUrl
            , skin: 'row' //表格风格
            , even: true
            , page: true //是否显示分页
            , limits: [15, 30, 50]
            , limit: 15 //每页默认显示的数量
            , id: "InvTable"
            });
   
            table.on('tool(list)', function (obj) {
                var data = obj.data,
                    layEvent = obj.event;
                if (layEvent == 'icEdit') {
                    if (data.isSync == "Y") {
                        layer.msg("同步数据禁止修改");
                    } else {
                        id = data.id
                        var webUrl = '../Basis/UpdateInventoryInfo?dataId=' + data.id + '&inventory=' + inventory;
                        var title = data.proName + "-修改"
                        NewOpenPage(webUrl, title, "65%", "80%", "InvTable", currPage, dUrl);
                    }
                } else if (layEvent == 'icDel') {
                    if (data.isSync == "Y") {
                        layer.msg("同步数据禁止删除");
                    } else {
                        layer.confirm('确定删除该档案？', function (index) {
                            $.ajax({
                                url: "../Basis/DelInventoryInfo",
                                data: { dataId: data.id },
                                type: 'post',
                                success: function (rsl) {
                                    if (rsl.Result) {
                                        layer.msg('删除成功！');
                                    } else {
                                        layer.msg('删除失败！');
                                    }
                                    //console.log(typeCode)
                                    loadData(typeCode)
                                }
                            })
                            layer.close('index')
                        })
                    }
                }
            });

        });
    }

    $(function () {
        WebPowersShow();
        $.ajax({
            url: "../Basis/venClassNavigation",
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    loadTree(data.Data);
                } else {
                    layer.msg(data.Message);
                }
            }
        });

        loadData("")
    })

    var typeCode = ''
    var inventory = ''

    function loadTree(data) {
        var tree = layui.tree;
        var layer = layui.layer;
        var util = layui.util;
        //开启节点操作图标
        tree.render({
            elem: '#treeNav'
          , data: data
          , click: function (obj) {
              //console.log(obj.data)
              typeCode = obj.data["id"]
              inventory = obj.data["title"]
              loadData(obj.data["id"]);
          }
        });
    }
    /**
    数据同步方法
    **/
    function syncData() {
        var index = layer.load(1, { shade: [0.7, '#393D49'] }, { shadeClose: true }); //0代表加载的风格，支持0-2
        $.ajax({
            url: "../Basis/SyncData",
            data: { dataType: "ven" },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    layer.msg("同步执行成功");
                } else {
                    layer.msg(data.Message);
                }
                layer.close(index);
            }
        });
    }

    /**
    存货自由项同步方法
    **/
    function syncDef() {
        var index = layer.load(1, { shade: [0.7, '#393D49'] }, { shadeClose: true }); //0代表加载的风格，支持0-2
        $.ajax({
            url: "../Basis/SyncData",
            data: { dataType: "def" },
            dataType: "json",
            type: "POST",
            success: function (data) {
                if (data.Result) {
                    layer.msg("同步执行成功");
                } else {
                    layer.msg(data.Message);
                }
                layer.close(index);
            }
        });
    }

    /**
    数据添加方法
    **/
    var id = ''
    function addData() {
        //console.log(typeCode)
        if (typeCode != '') {
            //InfoOpenPage('../Basis/UpdateInventoryInfo?dataId=0&typeCode=' + typeCode, title + "-新增存货档案", "65%", "80%");
            var webUrl = '../Basis/UpdateInventoryInfo?dataId=0&typeCode=' + typeCode + '&inventory=' + inventory;
            //console.log(webUrl)
            var title = inventory + "-添加"
            var dUrl = "../Basis/GetDataList?dataType=ven&typesCode=" + typeCode    
            NewOpenPage(webUrl, title, "65%", "80%", "InvTable", currPage, dUrl);

        } else {
            alert("请先选择存货大类！")
        }
    }
</script>
